import UIKit
import AssetsLibrary

// cell默认颜色: Boder, 填充颜色
private let normalColor = UIColor(red: 78.0 / 255.0, green: 183.0 / 255.0, blue: 186.0 / 225.0, alpha: 1.0)

enum ImagePickerType {
    case Default
    case Tag
    case Check
}

// 默认值
let kLeftButtonTitle = "Cancel"
let kPickerControllerTitle = "Choose Photo"
let kRightButtonTitle = "Done"
let kNumberOfImagePerRow = 4
let kMaxByteSize: Int64 = 10 * 1024 * 1024
let kMaxSelectedCount = 10

public class ImagePickerViewController: UINavigationController {
    
    var leftButtonTitle: String = kLeftButtonTitle
    var pickerControllerTitle: String = kPickerControllerTitle
    var rightButtonTitle: String = kRightButtonTitle
    var perRowNumber = kNumberOfImagePerRow
    // MARK: - 开放的属性
    var maxSelectedCount = kMaxSelectedCount
    // 选择图片最大 10M
    var maxByteSize = kMaxByteSize
    // cell 选中边框颜色
    var borderColor = normalColor
    // cell 选中边上角label 填充颜色
    var fillLabelColor = normalColor
    weak var pickerDelegate: ImageContentViewControllerDelegate?
    var authorizationAlertView: UIAlertView?
    var maxSelectedAlertView: UIAlertView?
    var maxByteSizeAlertView: UIAlertView?
    var groupType = ALAssetsGroupSavedPhotos
    // 选择的样式 类型
    var type: ImagePickerType = .Default
    
    // MARK: - 系统方法
    override public func viewDidLoad() {
        super.viewDidLoad()
 
        let contentVC = AlbumTableViewController()
        contentVC.groupType = groupType
        contentVC.pickerDelegate = pickerDelegate
        contentVC.borderColor = borderColor
        contentVC.fillLabelColor = fillLabelColor
        contentVC.maxSelectedCount = maxSelectedCount
        contentVC.perRowNumber = perRowNumber
        contentVC.leftButtonTitle = leftButtonTitle
        contentVC.pickerControllerTitle = pickerControllerTitle
        contentVC.rightButtonTitle = rightButtonTitle
        contentVC.authorizationAlertView = authorizationAlertView
        contentVC.maxSelectedAlertView = maxSelectedAlertView
        contentVC.maxByteSizeAlertView = maxByteSizeAlertView
        contentVC.type = type
        
        let nav = UINavigationController(rootViewController: contentVC)
        addChildViewController(nav)
        view.addSubview(nav.view)
    }
    
    deinit {
        print("ImagePickerViewController: deinit")
        removeAllChildViewController()
    }
}
